package com.wangbo.box.bridge;

/**
 * 桥接模式
 *
 * 桥接（Bridge）模式的定义如下：将抽象与实现分离，使它们可以独立变化。它是用组合关系代替继承关系来实现，从而降低了抽象和实现这两个可变维度的耦合度。
 */
public class BridgePattern {


    interface Subject{
        void show();
    }

    static class SubjectA implements Subject{

        @Override
        public void show() {
            System.out.println("subject A");
        }
    }

    static class SubjectB implements Subject{

        @Override
        public void show() {
            System.out.println("subject B");
        }
    }
    static abstract class AbstractProduct{
        Subject subject;

        public AbstractProduct(Subject subject) {
            this.subject = subject;
        }

        abstract void show();
    }

    static class Product extends AbstractProduct{

        public Product(Subject subject) {
            super(subject);
        }

        @Override
        void show() {
            System.out.println();
            subject.show();
        }
    }

    public static void main(String[] args) {
        Product product = new Product(new SubjectA());
        product.show();
    }


}
